1 using UnityEngine;
2 using
System;
3 using
System.Collections;
4
5
6 public
class Vector4TweenProperty : AbstractTweenProperty, IGenericProperty
7 {
8     
public string propertyName { get; private set; }
9     
private Action<Vector4> _setter;
10     
11     
protected Vector4 _originalEndValue;
12     
protected Vector4 _startValue;
13     
protected Vector4 _endValue;
14     
protected Vector4 _diffValue;
15     
16     
17     
public Vector4TweenProperty( string propertyName, Vector4 endValue, bool isRelative = false ) : base( isRelative )
18     {
19         
this.propertyName = propertyName;
20         _originalEndValue = endValue;
21     }

22     
23     
24     ///
<summary>
25     ///
validation checks to make sure the target has a valid property with an accessible setter
26     ///
</summary>
27     
public override bool validateTarget( object target )
28     {
29         
// cache the setter
30         _setter = GoTweenUtils.setterForProperty<Action<Vector4>>( target, propertyName );
31         
return _setter != null;
32     }
33
34     
35     
public override void prepareForUse()
36     {
37         
// retrieve the getter
38         
var getter = GoTweenUtils.getterForProperty<Func<Vector4>>( _ownerTween.target, propertyName );
39         
40         _endValue = _originalEndValue;
41         
42         
// if this is a from tween we need to swap the start and end values
43         
if( _ownerTween.isFrom )
44         {
45             _endValue = _startValue;
46             _endValue = getter();
47         }
48         
else
49         {
50             _startValue = getter();
51         }
52         
53         
// prep the diff value
54         
if( _isRelative && !_ownerTween.isFrom )
55             _diffValue = _endValue;
56         
else
57             _diffValue = _endValue - _startValue;
58     }
59     
60     
61     
public override void tick( float totalElapsedTime )
62     {
63         
var easedTime = _easeFunction( totalElapsedTime, 0, 1, _ownerTween.duration );
64         
var vec = GoTweenUtils.unclampedVector4Lerp( _startValue, _diffValue, easedTime );
65         
66         _setter( vec );
67     }
68
69 }



Trò chơi Angry Birds trong UNITY Engine 31.718 lượt xem

Gõ tìm kiếm nhanh...